import unittest
from selenium import webdriver
from Business.url import url_index
from Common.selenium_tools import get_browser


class Login_Test(unittest.TestCase):
    """
    1、打开浏览器
    2、打开首页
    3、点击请登录
    4、输入账号
    5、输入密码
    6、点击立即登录
    7、断言
    8、关闭浏览器
    """

    def setUp(self):
        # self.driver = webdriver.Chrome()
        # self.driver.maximize_window()
        # self.driver.implicitly_wait(3)
        self.driver = get_browser()

    def tearDown(self):
        self.driver.quit()

    def test_Login_1(self):
        username = "liu01"
        password = "123456"
        self.driver.get(url_index)
        self.driver.find_element_by_partial_link_text("请登录").click()
        self.driver.find_element_by_name("username").send_keys(username)
        self.driver.find_element_by_name("password").send_keys(password)
        self.driver.find_element_by_name("submit").click()
        # 断言
        text = self.driver.find_element_by_xpath('//*[@class="box_1"]//p[1]').text
        self.assertEqual("登录成功", text)
        text = self.driver.find_element_by_xpath('//*[@class="f4_b"]').text
        self.assertEqual(username, text)

    def test_Login_2(self):
        username = "liu01"
        password = "123456789"
        self.driver.get(url_index)
        self.driver.find_element_by_partial_link_text("请登录").click()
        self.driver.find_element_by_name("username").send_keys(username)
        self.driver.find_element_by_name("password").send_keys(password)
        self.driver.find_element_by_name("submit").click()
        # 断言
        text = self.driver.find_element_by_xpath('//*[@class="box_1"]//p[1]').text
        self.assertEqual("用户名或密码错误", text)
